Write(Byte[],Int32,Int32) Method
Writes a sequence of bytes to the current
OracleLob stream, and advances the current position within this stream by the number of bytes written.
In this example data is written to
OracleLob object from a stream.
public void UploadBlob(OracleConnection myConnection)
{
FileStream fs = new FileStream("D:\\Tmp\\_Water.bmp", FileMode.Open, FileAccess.Read);
BinaryReader r = new BinaryReader(fs);
myConnection.Open();
OracleLob myLob = new OracleLob(myConnection,OracleDbType.Blob);
int streamLength = (int)fs.Length;
myLob.Write(r.ReadBytes(streamLength), 0, streamLength);
OracleCommand myCommand = new OracleCommand("INSERT INTO Pictures (ID, PicName, Picture) VALUES(1,'Water',:Pictures)", myConnection);
OracleParameter myParam = myCommand.Parameters.Add("Pictures", OracleDbType.Blob);
myParam.OracleValue = myLob;
try
{
Console.WriteLine(myCommand.ExecuteNonQuery() + " rows affected.");
}
finally
{
myConnection.Close();
r.Close();
fs.Close();
}
}
Public Sub UploadBlob(ByVal myConnection As OracleConnection)
Dim fs As FileStream = New FileStream("D:\Tmp\_Water.bmp", FileMode.Open, FileAccess.Read)
Dim r As BinaryReader = New BinaryReader(fs)
myConnection.Open()
Dim myLob As OracleLob = New OracleLob(myConnection, OracleDbType.Blob)
Dim streamLength As Int32 = fs.Length
myLob.Write(r.ReadBytes(streamLength), 0, streamLength)
Dim myCommand As OracleCommand = New OracleCommand("INSERT INTO Pictures (ID, PicName, Picture) VALUES(1,'Water',:Pictures)", myConnection)
Dim myParam As OracleParameter = myCommand.Parameters.Add("Pictures", OracleDbType.Blob)
myParam.OracleValue = myLob
Try
Console.WriteLine(myCommand.ExecuteNonQuery() & " rows affected.")
Finally
myConnection.Close()
r.Close()
fs.Close()
End Try
End Sub
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2